package toanstt.com.menu;

import toanstt.com.MatchUp.App;
import toanstt.com.MatchUp.ButtonCenter;
import toanstt.com.MatchUp.MainActivity;
import toanstt.com.MatchUp.Notice;
import toanstt.com.MatchUp.SCR;
import toanstt.com.MatchUp.Sound2;
import toanstt.com.MatchUp.T;
import toanstt.com.gameplay.G;
import android.content.Intent;
import android.graphics.Canvas;
import android.net.Uri;
import android.view.MotionEvent;

public class M
{
	int temp_x,temp_y;
	int action, actionCode;
	ButtonCenter[] buttons;
	public M()
	{
		if(T.ISHORIZONTAL)
		{
			if(T.DISPLAY_WIDTH < 400)
			{
			buttons = new ButtonCenter[5];
			buttons[0]= new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[0],T.DISPLAY_WIDTH/2,(int)((1.4)*4*T.U2));
			for(int i =1;i<4;i++)
				buttons[i] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[i-1],T.DISPLAY_WIDTH/2,(int)((i+1.4)*3.5*T.U2));
			buttons[4] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[3],T.DISPLAY_WIDTH/2,(int)(T.DISPLAY_HEIGHT - (int)(10*T.U2)));
			}
			else
			{
				buttons = new ButtonCenter[5];
				buttons[0]= new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[0],T.DISPLAY_WIDTH/2,(int)((2)*3.5*T.U2));
				buttons[1]= new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[0],T.DISPLAY_WIDTH/2,(int)((3)*3.5*T.U2));
				for(int i =2;i<4;i++)
					buttons[i] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[i-1],T.DISPLAY_WIDTH/2,(int)((i+2)*3.5*T.U2));
				buttons[4] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[3],T.DISPLAY_WIDTH/2,(int)(T.DISPLAY_HEIGHT - 50 - (int)(2*T.U2)));
			}
		}
		else
		{
			buttons = new ButtonCenter[5];
			buttons[0]= new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[19],T.DISPLAY_WIDTH/2,(int)((1.5)*4*T.U2));
			for(int i =1;i<4;i++)
				buttons[i] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[i-1],T.DISPLAY_WIDTH/2,(int)((i+1.5)*4*T.U2));
			buttons[4] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[3],T.DISPLAY_WIDTH/2,(int)(T.DISPLAY_HEIGHT - (int)(5*T.U2)));
		}
	}
	int d;
	public void Draw(Canvas canvas)
	{
		if(T.THEME_WHITE == true)
			canvas.drawBitmap(T.TBITMAP_THEME_WHITE.bitmap[0], 0, 0, null);
		else
			canvas.drawBitmap(T.TBITMAP_THEME_BLACK.bitmap[0], 0, 0, null);
		
		canvas.drawBitmap(T.TBITMAP_BANER.bitmap[0],T.DISPLAY_WIDTH/2 - T.TBITMAP_BANER.bitmap[0].getWidth()/2, (int)(T.U2/2), null);
		for(d =0;d<5;d++)
			buttons[d].Draw2(canvas);
	}
	int t;
	public void touch(MotionEvent mo)
	{
		
		action = mo.getAction();
		actionCode = action & MotionEvent.ACTION_MASK;
		temp_x = (int)mo.getX();
		temp_y = (int)mo.getY();
		
		for(t =0;t<5;t++)
		{
			if(buttons[t].Kick(mo))
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				if(t==0)
					//T.SCREEN = SCR.NEWGAME;
				{
					if(T.SCREEN_TEMP == -1)
					{
						T.SCREEN_TEMP = SCR.NEWGAME;
						T.ALPHA = 20;
					}
					
					
					
					//G.savegame.LoadGame();
				}
				else if(t==1)
				{
					if(T.SCREEN_TEMP == -1)
					{
						T.SCREEN_TEMP =SCR.HUONGDAN;
						T.ALPHA = 20;
					}
				}
				else if(t==4)
				{
					if(T.SCREEN_TEMP == -1)
						T.notice.DoNotice(Notice.QUIT, 0);
					
				}
				else if(t==3)
				{
					if(T.SCREEN_TEMP == -1)
					{
						Uri uri = Uri.parse("https://play.google.com/store/apps/developer?id=CAOGIA++MOBILE+LTD.");
						MainActivity.activity.startActivity(new Intent(Intent.ACTION_VIEW, uri));
					}
				}
				else if(t==2)
				{
					if(T.SCREEN_TEMP == -1)
					{
						T.SCREEN_TEMP =SCR.SETTING;
						T.ALPHA = 20;
					}
				}	
				
				break;
			}
			
		}
		int d2;
		switch(action)
		{
			//case MotionEvent.ACTION_DOWN:
				//if(temp_y < 50)
					//if(temp_x > T.DISPLAY_WIDTH -50)
						//MainActivity.activity.finish();
			//break;
			
			case MotionEvent.ACTION_UP:
				for(d2 =0;d2<5;d2++)
					buttons[d2].anpla = 255;
			break;
			
			//case MotionEvent.ACTION_MOVE:
			//break;

		}
	}
}
